//


#import "NT_LeftTableView.h"
#import "NT_LeftView.h"

//
@interface NT_LeftTableView ()

/** */
@property (nonatomic, strong) UIView *backview;

@end

@implementation NT_LeftTableView

- (instancetype)init {
    if ([super init]) {
        self.frame = CGRectMake(-kMainScreenWidth, 0, kMainScreenWidth, kMainScreenHeight);
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(Action) name:@"hidder" object:nil];
        [self initUI];
        [self initTableview];
        
    }return self;
}
//MARK:
- (void)initUI {
    //
    self.backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kMainScreenWidth-kRelativeWidth(100), kMainScreenHeight)];
    self.backview.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.backview];
    
}
//MARK:创建leftTableview
- (void)initTableview {
    NT_LeftView *vc = [[NT_LeftView alloc]initWithFrame:CGRectMake(0, 0, kMainScreenWidth-kRelativeWidth(100), kMainScreenHeight)];
    [self.backview addSubview:vc];
    //
    __weak typeof(self) weakSelf = self;
    vc.leftViewBlock = ^(NSIndexPath * _Nonnull path ,NSString *text) {
        [weakSelf Action];
        if ([weakSelf.delegate respondsToSelector:@selector(setCellIndex:text:)]) {
            [weakSelf.delegate setCellIndex:path text:text];
        }
    };
}


#pragma mark - 弹出 -
- (void)showView
{
    UIWindow *rootWindow = [UIApplication sharedApplication].keyWindow;
    [rootWindow addSubview:self];
    [self creatShowAnimation];
}
//MARK:动画
- (void)creatShowAnimation
{
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^{
        self.frame = CGRectMake(0, 0, kMainScreenWidth, kMainScreenHeight);
    } completion:^(BOOL finished) {
    }];
}
//MARK:手势
- (void)Action {
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^{
        self.frame = CGRectMake(-kMainScreenWidth, 0, kMainScreenWidth, kMainScreenHeight);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self Action];
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
